User   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 91
dl 0
loc 106
c 0
b 0
f 0
rs 10

13 Functions

Rating   Name   Duplication   Size   Complexity  
A getId 0 3 1
A getLastName 0 3 1
A isAdministrativeEditable 0 3 1
A getEmail 0 3 1
A getRole 0 3 1
A getPassword 0 3 1
A getFirstName 0 3 1
A getFullName 0 3 1
A getUserAdministrative 0 3 1
A getApiToken 0 3 1
A update 0 5 1
A updateRole 0 3 1
A updatePassword 0 3 1
1
import {
2
  Entity,
3
  Column,
4
  PrimaryGeneratedColumn,
5
  Index,
6
  OneToOne,
7
  JoinColumn
8
} from 'typeorm';
9
import { UserAdministrative } from './UserAdministrative.entity';
10
11
export enum UserRole {
12
  COOPERATOR = 'cooperator',
13
  EMPLOYEE = 'employee',
14
  ACCOUNTANT = 'accountant'
15
}
16
17
@Entity()
18
export class User {
19
  @PrimaryGeneratedColumn('uuid')
20
  private id: string;
21
22
  @Column({ type: 'varchar', nullable: false })
23
  private firstName: string;
24
25
  @Column({ type: 'varchar', nullable: false })
26
  private lastName: string;
27
28
  @Column({ type: 'varchar', unique: true, nullable: false })
29
  private email: string;
30
31
  @Index('api-token')
32
  @Column({ type: 'varchar', nullable: true })
33
  private apiToken: string;
34
35
  @Column({ type: 'varchar', nullable: false })
36
  private password: string;
37
38
  @Column('enum', { enum: UserRole, nullable: false })
39
  private role: UserRole;
40
41
  @OneToOne(
42
    type => UserAdministrative,
43
    userAdministrative => userAdministrative.user,
44
    { nullable: true }
45
  )
46
  @JoinColumn()
47
  public userAdministrative: UserAdministrative;
48
49
  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
50
  private createdAt: Date;
51
52
  constructor(
53
    firstName: string,
54
    lastName: string,
55
    email: string,
56
    apiToken: string,
57
    password: string,
58
    role: UserRole,
59
    userAdministrative?: UserAdministrative
60
  ) {
61
    this.firstName = firstName;
62
    this.lastName = lastName;
63
    this.email = email;
64
    this.apiToken = apiToken;
65
    this.password = password;
66
    this.role = role;
67
    this.userAdministrative = userAdministrative;
68
  }
69
70
  public getId(): string {
71
    return this.id;
72
  }
73
74
  public getFirstName(): string {
75
    return this.firstName;
76
  }
77
78
  public getLastName(): string {
79
    return this.lastName;
80
  }
81
82
  public getEmail(): string {
83
    return this.email;
84
  }
85
86
  public getApiToken(): string {
87
    return this.apiToken;
88
  }
89
90
  public getPassword(): string {
91
    return this.password;
92
  }
93
94
  public getRole(): UserRole {
95
    return this.role;
96
  }
97
98
  public isAdministrativeEditable(): boolean {
99
    return this.role !== UserRole.ACCOUNTANT;
100
  }
101
102
  public getFullName(): string {
103
    return `${this.firstName} ${this.lastName}`;
104
  }
105
106
  public getUserAdministrative(): UserAdministrative {
107
    return this.userAdministrative;
108
  }
109
110
  public update(firstName: string, lastName: string, email: string): void {
111
    this.firstName = firstName;
112
    this.lastName = lastName;
113
    this.email = email;
114
  }
115
116
  public updatePassword(password: string): void {
117
    this.password = password;
118
  }
119
120
  public updateRole(role: UserRole): void {
121
    this.role = role;
122
  }
123
}
124